<?php
/*
	About: 
	Date: 23.05.2007

	Copyright 2006-2007  Alex Djachenko
	Authors: Alex Djachenko
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

    Принять участие в разработке или скачать новую версию вы можете на сайте
    http://code.google.com/p/my-site-framework/
*/
class addressbook_addf_users extends addressbook_addf 
{
    protected $processor;
    protected $cfg;
    function __construct($Processor,$cfg)
    {
        $this->processor = $Processor;
        $this->cfg = $cfg;
    }
    function get($assoc_id)
    {
        $obj = $this->processor->query('getClsUsers',$assoc_id);
        if (!$obj or sharpobj_iserror($obj))
        {
            return $obj;
        }
        $obj2 = $this->getObj();
        $obj2->setP($obj->getP('user_id'),'user_id');
        return $obj2;
    }
    function save($obj,$assoc_id=null)
    {
        if (!$assoc_id)
        {
            $assoc_id = sharpobj_conv_int_obj($obj->getId());
        }else
        {
            $assoc_id = sharpobj_conv_int_obj($assoc_id); 
        }
        
        if ($obj2 = $this->processor->query('getClsUsers',$assoc_id))
        {
            // Обновляем
            $obj2->setP($obj->getP('user_id'),'user_id');
            return $this->processor->query('sc_update_addf_cls_users',$obj2);
        }else
        {
            // Создаем

            $obj2 = $this->processor->query('sc_getObj_addf_cls_users');

            // Переводим объект в формат хранилища
            $obj2->setP($obj->getP('user_id'),'user_id');
            $obj2->setP($assoc_id->getP(),'assoc_id');
            // 	Сохраняем объект в хранилище
            return $this->processor->query('sc_insert_addf_cls_users',$obj2);
        }

    }
    function del($assoc_id)
    {
        $obj = $this->processor->query('getClsUsers',$assoc_id);
        return $this->processor->query('sc_delete_addf_cls_users',$obj);
    }
    function getObj()
    {
        $obj = new sharpobj_data_item_data();
        $obj->addItem('user_id','int');
        return $obj;
    }
}
?>